---
layout: "default"
title: "RangeGenerator"
description: "Swift documentation for 'RangeGenerator': A generator over the elements of Range&lt;T&gt;."
keywords: "RangeGenerator,struct,swift,documentation,generate,next,endIndex,startIndex,Element,Generator"
root: "/v1.2"
---

<div class="intro-declaration"><code class="language-swift">struct RangeGenerator&lt;T : ForwardIndexType&gt;</code></div>

<div class="discussion comment">
    <p>A generator over the elements of <code>Range&lt;T&gt;</code></p>
</div>

<table class="standard">
<tr>
<th id="inheritance">Inheritance</th>
<td>
<code class="inherits">GeneratorType, SequenceType, _SequenceType, _Sequence_Type</code>
<span class="viz"><a href="hierarchy/">View Protocol Hierarchy &rarr;</a></span>
</td>
</tr>

<tr>
<th id="aliases">Associated Types</th>
<td>
<span id="aliasesmark"></span>
<div class="declaration">
<code class="language-swift">Element = T</code>
<div class="comment">
    <p>The type of element returned by <code>next()</code>.</p>
</div>
</div>
<div class="declaration">
<code class="language-swift">Generator = RangeGenerator&lt;T&gt;</code>
<div class="comment">
    <p>A type whose instances can produce the elements of this
sequence, in order.</p>
</div>
</div>
</td>
</tr>


<tr>
<th>Import</th>
<td><code class="language-swift">import Swift</code></td>
</tr>

</table>


<h3>Initializers</h3>
<div class="declaration" id="init_">
<a class="toggle-link" data-toggle="collapse" href="#comment-init_">init(<wbr>_:)</a><div class="comment collapse" id="comment-init_"><div class="p">
    <p>Construct an instance that traverses the elements of <code>bounds</code></p>

    <h4>Declaration</h4>    
    <code class="language-swift">init(_ bounds: Range&lt;T&gt;)</code>

    </div></div>
</div>


<h3>Instance Variables</h3>
<div class="declaration" id="var-endindex_-t">
<a class="toggle-link" data-toggle="collapse" href="#comment-var-endindex_-t">var endIndex: T</a><div class="comment collapse" id="comment-var-endindex_-t"><div class="p">
    <p>The upper bound of the remaining range; not included in the
generated sequence.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">var endIndex: T { get set }</code>

    </div></div>
</div>
<div class="declaration" id="var-startindex_-t">
<a class="toggle-link" data-toggle="collapse" href="#comment-var-startindex_-t">var startIndex: T</a><div class="comment collapse" id="comment-var-startindex_-t"><div class="p">
    <p>The lower bound of the remaining range.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">var startIndex: T { get set }</code>

    </div></div>
</div>



<h3>Instance Methods</h3>
<div class="declaration" id="func-generate">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-generate">func generate()</a>
        
<div class="comment collapse" id="comment-func-generate"><div class="p">
    <p><code>RangeGenerator</code> is also a <code>SequenceType</code>, so it
<code>generate</code>&#39;s a copy of itself</p>

    <h4>Declaration</h4>    
    <code class="language-swift">func generate() -&gt; RangeGenerator&lt;T&gt;</code>
    
    
</div></div>
</div>
<div class="declaration" id="func-next">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-next">mutating func next()</a>
        
<div class="comment collapse" id="comment-func-next"><div class="p">
    <p>Advance to the next element and return it, or <code>nil</code> if no next
element exists.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">mutating func next() -&gt; T?</code>
    
    
</div></div>
</div>


